package com.lk.jmeter.socket;

import java.net.Socket;

import com.lk.jmeter.util.ClientUtil;
import com.lk.jmeter.util.MsgUtil;

public class BusinessRecordTest {
	
	
	public static byte[] getBusinessRecordMsg(int type, int methodType, String data) throws Exception{
//		JSONArray array = new JSONArray();
//		JSONObject dataJson = new JSONObject();
//		dataJson.put("account", "62220214053210");
//		dataJson.put("ID_num", "330326199105140622");
//		dataJson.put("mobile", "18259067964");
//		dataJson.put("name", "张三");
//		array.add(dataJson);
//		
//		JSONObject json = new JSONObject();
//		json.put("serial","dev_1");
//		json.put("business","1001");
//		json.put("outlets","000002");
//		json.put("data", array.toString());
		
		return MsgUtil.createMsg((byte) type,(byte) methodType, data);
	}
	
	public static String sendMsg(String ip, int port, int type, int methodType, String msg){
		//连接socket
		try {
			Socket clientSocket = new Socket(ip, port);
			ClientUtil client = new ClientUtil(clientSocket, getBusinessRecordMsg(type, methodType, msg));
			byte[] receiveMsg = client.run();
			if(receiveMsg != null){
				return MsgUtil.doWork(receiveMsg);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "null";
	}

}
